<template>
  <div class="app-container">
    <act-dialog @close="close" v-if="showDialog" :activityId="activityId" @update="getActivityList"></act-dialog>
    <el-button type="primary" icon="el-icon-plus" class="button" @click="showDialog=!showDialog">添加活动</el-button>
    <el-table :data="activityData" border style="width: 100%" class="actTable">
      <el-table-column fixed prop="activityName" label="活动名称" width="150"></el-table-column>
      <el-table-column prop="activityDesc" label="活动描述" min-width="120"></el-table-column>
      <el-table-column prop="activityPicUrl" label="活动banner" width="250">
        <template slot-scope="scope"> 
          <img :src="scope.row.activityPicUrl" class="banner">
        </template>
      </el-table-column>
      <el-table-column prop="activityUrl" label="活动H5链接" min-width="120"></el-table-column>
      <el-table-column prop="activityStatusText" label="活动状态" width="300"></el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row)" type="primary" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import actDialog from './dialog'
import { getActivityList } from 'api/activity'
export default {

  components: {
    actDialog
  },
  data() {
    return {
      activityData: [],
      showDialog: false,
      activityId: ''
    }
  },
  created() {
    this.getActivityList()
  },
  methods: {
    edit(row) {
      console.log(row)
      this.activityId = row.activityId
      this.showDialog = true
    },
    async getActivityList() {
      this.close()
      try {
        let back = await getActivityList()
        back = back.data
        if (back.resultCode === '200') {
          const arr = [...back.result]
          arr.forEach(element => {
            if (element.activityStatus === 1) {
              element.activityStatusText = '未开始'
            } else if (element.activityStatus === 2) {
              element.activityStatusText = '已开始'
            } else if (element.activityStatus === 3) {
              element.activityStatusText = '已下架'
            }
          })
          this.activityData = arr
        }
      } catch (err) {
        this.$alert('请求出错', '提示')
      }
    },
    close() {
      this.activityId = ''
      this.showDialog = false
    }
  }
}
</script>
<style scoped lang="scss">
  .actTable{
    margin-top:20px;
  }
  .banner {
    width: 200px;
  }
</style>
